package com.nf.health.app.intervention_details.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.intervention_details.bean.UserHealthInfoBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 恩福 on 2016/11/10.
 * 个人健康信息汇总检测结果 Adapter
 *
 * @auther changpeng
 * @email obj_cp@126.com
 */

public class SchemeResultAdapter<T> extends RecyclerView.Adapter {
    private static final int HEAD_VIEW = 0;
    private T result;

    private Context mContext;

    public SchemeResultAdapter(Context context,T result) {
        this.mContext = context;
        this.result = result;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.health_info_scheme_result_item, parent, false);
        return new SchemeResultHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        SchemeResultHolder schemeResultHolder = (SchemeResultHolder)holder;
        if(HEAD_VIEW == position){
            schemeResultHolder.tvTarget.setText("检查指标");
            schemeResultHolder.tvNewResult.setText("最新结果");
            schemeResultHolder.tvReference.setText("参考值");
            return;
        }
        schemeResultHolder.tvNewResult.setTextColor(mContext.getResources().getColor(R.color.theme_color));
        if(result instanceof UserHealthInfoBean.MonitordataBean){
            UserHealthInfoBean.MonitordataBean bean = (UserHealthInfoBean.MonitordataBean) result;
            if(1 == position){
                schemeResultHolder.tvTarget.setText("血压");
                schemeResultHolder.tvNewResult.setText(bean.getBlood());
                schemeResultHolder.tvReference.setText("120/88mmHg");
            }
            if(2 == position){
                schemeResultHolder.tvTarget.setText("血糖");
                schemeResultHolder.tvNewResult.setText(bean.getBloodglucose());
                schemeResultHolder.tvReference.setText("<6.1mmol/L");
            }
            if(3 == position){
                schemeResultHolder.tvTarget.setText("BMI");
                schemeResultHolder.tvNewResult.setText(bean.getBmi());
                schemeResultHolder.tvReference.setText("18.5≤BMI<24");
            }
        }

        if(result instanceof UserHealthInfoBean.LifewayBean){
            UserHealthInfoBean.LifewayBean bean = (UserHealthInfoBean.LifewayBean) result;
            if(1 == position){
                schemeResultHolder.tvTarget.setText("体力活动水平");
                schemeResultHolder.tvNewResult.setText(bean.getStrength());
                schemeResultHolder.tvReference.setText("充分");
            }
            if(2 == position){
                schemeResultHolder.tvTarget.setText("膳食习惯评价等级");
                schemeResultHolder.tvNewResult.setText(bean.getFoodhabit());
                schemeResultHolder.tvReference.setText("优秀");
            }
            if(3 == position){
                schemeResultHolder.tvTarget.setText("吸烟情况");
                schemeResultHolder.tvNewResult.setText(bean.getSmoke());
                schemeResultHolder.tvReference.setText("不吸烟");
            }
            if(4 == position){
                schemeResultHolder.tvTarget.setText("饮酒情况");
                schemeResultHolder.tvNewResult.setText(bean.getDrink());
                schemeResultHolder.tvReference.setText("酒精量≤25克/天");
            }
        }
    }

    @Override
    public int getItemCount() {
        if(result == null){
            return 0;
        }
        if(result instanceof UserHealthInfoBean.MonitordataBean){
            return 4;
        }

        if(result instanceof UserHealthInfoBean.LifewayBean){
            return 5;
        }
        return 0;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    class SchemeResultHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_target)
        TextView tvTarget;
        @Bind(R.id.tv_new_result)
        TextView tvNewResult;
        @Bind(R.id.tv_reference)
        TextView tvReference;
        @Bind(R.id.ll_container)
        LinearLayout llContainer;

        public SchemeResultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
